using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Text;

namespace trainstorm.InstanceClass
{
	public class Obstacle
	{
		public Vector2 pos;
		public Vector2 vel;
		protected Texture2D gambar;
		protected float scale;

		// constructor
		public Obstacle()
		{
			pos = new Vector2(0);
			vel = new Vector2(0);
			gambar = null;
			scale = 0f;
		}
		public Obstacle(float x, float y, Texture2D input)
		{
			pos = new Vector2(x, y);
			vel = new Vector2(0);
			gambar = input;
			scale = 1f;
		}
		public Obstacle(Game1 game1, int obsNumber, Vector2 velocity, Vector2 position)
		{
			gambar = game1.getInsManager().getObstacles(obsNumber);
			pos = position;
			vel = velocity;
		}

		//getter setter
		public float getX()
		{
			return pos.X;
		}
		public float getY()
		{
			return pos.Y;
		}
		public float getVelX()
		{
			return vel.X;
		}
		public float getVelY()
		{
			return vel.Y;
		}
		public float getScale()
		{
			return scale;
		}
		public Texture2D getSprite()
		{
			return gambar;
		}

		public void setX(float x)
		{
			pos.X = x;
		}
		public void setY(float y)
		{
			pos.Y = y;
		}
		public void setVelX(float x)
		{
			vel.X = x;
		}
		public void setVelY(float y)
		{
			vel.Y = y;
		}
		public void setSprite(Texture2D sprite)
		{
			gambar = sprite;
		}

		//update
		public virtual void update(GameTime gameTime, float screenVel)
		{
			pos.X -= ((float)(gameTime.ElapsedGameTime.TotalSeconds) * (vel.X + -screenVel));
			pos.Y += ((float)(gameTime.ElapsedGameTime.TotalSeconds) * vel.Y);
		}

		//draw
		public virtual void Draw(SpriteBatch batch)
		{
			if (pos.X + gambar.Width < 480)
			{
				batch.Draw(gambar, pos, null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 1f);
			}
			else if (pos.X > 480)
			{
				batch.Draw(gambar, new Vector2(pos.X - 480, pos.Y + 400), null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 1f);
			}
			else
			{
				batch.Draw(gambar, pos, null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 1f);
				batch.Draw(gambar, new Vector2(pos.X - 480, pos.Y + 400), null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 1f);
			}
		}
	}
}
